/**
 * 
 */
package com.cipe.cmrs.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Paymenttype;
import com.cipe.cmrs.model.User;
import com.cipe.cmrs.util.DateUtil;

/**
 * @author Incepio
 * 
 */
@Service
@Transactional
public class PaymenttypeService extends BaseService<Paymenttype> {

	@Autowired
	private UserService	userService;

	public Paymenttype savePaymenttype(Paymenttype paymenttype, Integer userId) {
		if (paymenttype != null) {
			User user = userService.findById(userId);
			Paymenttype dbPaymenttype = findById(paymenttype.getId());
			if (dbPaymenttype == null) {
				dbPaymenttype = new Paymenttype();
				dbPaymenttype.setCreatedBy(user);
				dbPaymenttype.setCreationDate(DateUtil.getCurrentDate());
			}
			dbPaymenttype.setUpdatedBy(user);
			dbPaymenttype.setUpdationDate(DateUtil.getCurrentDate());
			return merge(dbPaymenttype);
		}
		return null;
	}
	
	public List<Paymenttype> getActivePaymentTypes() {
		return dao.getResultList("FROM Paymenttype WHERE status = 'A' ORDER BY paymenttypename ASC");
	}
}
